/**============================================================================
 *
 * Author: luo1o1o1o 
 *
 * QQ: 330240995, PHONE: 17600071321
 *
 * Last modified: 2021-06-01 19:15
 *
 * Filename: _format.js
 *
 * Description: 数据格式化
 *
 ============================================================================**/
const { DEFAULT_PICTURE } = require('../conf/constant')
/**
 * @Author: luo1o1o1o
 * @QQ: 330240995, @PHONE: 17600071321
 * @Date: 2021-06-01 19:16
 * @desc: 用户默认头像
 */
function _formatUserPicture(obj) {
    if (obj.picture == null) {
        obj.picture = DEFAULT_PICTURE
    }
    return obj
}

/**
 * @Author: luo1o1o1o
 * @QQ: 330240995, @PHONE: 17600071321
 * @Date: 2021-06-01 19:23
 * @desc: 格式化用户信息
 */
function formatUser(list) {
    if (list == null) {
        // 防错误处理
        return list
    }

    if (list instanceof Array) {
        // 判断是否为数组
        // 数组 用户列表
        return list.map(_formatUserPicture)
    }

    // 单个对象
    let result = list
    return _formatUserPicture(result)
}
module.exports = {
    formatUser,
}
